#include "window.h"
#include "theme.h"
#include <sdl/sdl.h>

using namespace std;

Window::Window(){
    mTheme = Theme(); 
    mChild = 0;
    mBrother = 0;   
}

Window::Window(int x,int y, int w,int h){
    setDimension(x,y,w,h);
    mTheme = Theme(); 
    mChild = 0;
    mBrother = 0;
}

Window::Window(int x,int y, int w,int h,Theme theme){
    setDimension(x,y,w,h);
    mTheme = theme; 
    mChild = 0;
    mBrother = 0;
}

Window::~Window(){
    mChild = 0;
}

void Window::addChild(Window *wnd){
    if(mChild == 0) mChild = wnd;
    else mChild->addBrother(wnd);
}

void Window::addBrother(Window *wnd){
    if(mBrother == 0) mBrother = wnd;
    else mBrother->addBrother(wnd);
}

bool Window::checkFocus(Point p){
    mFocus = pointIn(p);
    return mFocus;
}

bool Window::isFocused(){
    return mFocus;
}

void Window::onFocus(){
    
}

void Window::onCreate(){
    
}

void Window::onDraw(){
}

void Window::draw(){
   // printf("%d,%d,%d,%d\n",getX(),getY(),getWidth(),getHeight());
    
    onDraw();
        
    SDL_Rect wrc = {getX(),getY(),getWidth(),getHeight()};
    SDL_FillRect(SDL_GetVideoSurface(),&wrc,mTheme.getBorderColor());
        
    SDL_Rect brc = {getX()+mTheme.getBorderSize(),
                    getY()+mTheme.getBorderSize(),
                    getWidth()-(mTheme.getBorderSize()*2),
                    getHeight()-(mTheme.getBorderSize()*2)};
    SDL_FillRect(SDL_GetVideoSurface(),&brc,mTheme.getBackgroundColor());
}
